<form name="lngForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	<table>
	<script type="text/javascript">
	function submitLng($language){
		document.lngForm.lng.value = $language;
		$_SESSION['lng'] = $language;
		document.lngForm.submit();
	}
	</script>
	<input type="hidden" name="lng" id="lng" />
	<?php		
		$languages = scandir('languages');
		foreach($languages as $language) 
		{
			if($language != $lng && $language!='..' && $language!='.' && $language != 'img')
			{				
				$l = str_replace('.php', '', $language);
				if($l != $lng)
				{
					echo '<td>';
					echo '<input class="flag" type="image" src="languages/img/'.$l.'.gif" ';
					echo 'value="'.$l.'" onClick="javascript: submitLng(\''.$l.'\')" /></td>';
				}
			}
		}
	?>
	</table>
</form>
